/**
 * Created with IntelliJ IDEA.
 * User: Kotone
 * Date: 2016/4/18
 * Time: 13:27
 * To change this template use File | Settings | File Templates.
 */
//alert(request('houseSource1Id'))
getHouseSource(request('houseSource1Id'), "leftHouseSource");
getHouseSource(request('houseSource2Id'), "middleHouseSource");
setTimeout('loadPage()', 100)
getHouseSource(request('houseSource3Id'), "rightHouseSource");
//setTimeout('loadPage()',100)
function getHouseSource(houseSourceId, position) {
    var result = $.ajax({
        type: "GET",
        url: ctx + "/houseSource/getHouseSource",
        data: {
            houseSourceId: houseSourceId
        },
        async: false,
        datatype: "json",
        success: function (response) {

        },
        error: function () {

        }
    });
    var houseSource = $.parseJSON(result.responseText).data;
    var result1 = $.ajax({
        type: "GET",
        url: ctx + "/building/getBuilding",
        data: {
            buildingId: houseSource.buildingId
        },
        async: false,
        datatype: "json",
        success: function (response) {

        },
        error: function () {

        }
    });
    var image = '';
    if (null != houseSource.images && '' != houseSource.images) {
        image = houseSource.images.split(',')[0]
    }
    var imageUrl = $.ajax({
        url: ctx + "/photos/getPhoto",
        data: {
            key: image
        },
        method: "get",
        async: false,
        success: function (response) {
            //alert(response.responseText)
            //var url = response;
            //document.getElementById(this.imageId).src = url + "|imageView2/1/w/320/h/180";
        },
        failure: function (response, opts) {

        }
    });
    console.log(imageUrl)
    imageUrl = imageUrl.responseText + "|imageView2/1/w/320/h/180";
    var building = $.parseJSON(result1.responseText).data;
    var tagsArray = new Array();
    var tags = "";
    if ("" != houseSource.buildingTags && null != houseSource.buildingTags) {
        tagsArray = houseSource.buildingTags.split(",");
        if (tagsArray.length > 0) {
            for (var i = 0; i < tagsArray.length; i++) {
                tags += '<span class="tip gray">' + tagsArray[i] + '</span>'
            }
        }
    }
    var floorsNum = "";
    var elevatorNum = "";
    var parkingPositionNum = "";
    if (null != building.floorsNum) {
        floorsNum = building.floorsNum;
    }
    if (null != building.elevatorNum) {
        elevatorNum = building.elevatorNum;
    }
    if (null != building.parkingPositionNum) {
        parkingPositionNum = building.parkingPositionNum;
    }

    var content =
        '<ul class="table-list">' +
        '<li><a href="' + ctx + '/share.html?houseSourceId=' + houseSource.houseSourceId + '"><img src="' + imageUrl + '"></a></li>' +
        '<li><a href="' + ctx + '/share.html?houseSourceId=' + houseSource.houseSourceId + '" class="fname">' + houseSource.buildingName + '</a></li>' +
        '<li class="tips">' + tags + '</li>' +
        '<li>' + houseSource.buildingAddress.city + '/' + houseSource.buildingAddress.district + '/' + building.businessCircleResponse.name + '</li>' +
        '<li>' + houseSource.unitPrice + '</li>' +
        '<li>' + houseSource.area + '</li>' +
        '<li><span class="c-orange">' + '约' + houseSource.totalPrice + '</span></li>' +
        '<li>' + houseSource.workplace + '</li>' +
        '<li>' + houseSource.standardStr + '</li>' +
        '<li>' + building.level + '</li>' +
        '<li>' + floorsNum + '</li>' +
        '<li>' + building.layerHeight + '</li>' +
        '<li>' + building.usablePercentage + '</li>' +
        '<li>' + elevatorNum + '</li>' +
        '<li>' + building.maintenanceFee + '</li>' +
        '<li>' + parkingPositionNum + '</li>' +
        '<li>' + building.totalArea + '</li>' +
        '</ul>';
    $('#' + position + '').append(
        content
    );


    //setTimeout('loadPage()',500)
}
function loadPage() {
    var swiper = new Swiper('.swiper-container2', {
        pagination: '.swiper-pagination',
        slidesPerView: 5,
        breakpoints: {
            1024: {
                slidesPerView: 3
            },
            768: {
                slidesPerView: 3
            },
            640: {
                slidesPerView: 2
            },
            320: {
                slidesPerView: 2
            }
        }
    });

    var maxh;
    var lt = $(".t-left").find("li");
    for (var i = 0; i < lt.length; i++) {//for循环左边模块
        var oa = [];
        $(".t-right .table-list").each(function () {
            //遍历右边模块，对应行高组成数组
            oa.push($(this).find("li").eq(i).height());
            $(this).find("li").eq(i - 1).each(function () {
                $(this).css("height", maxh);
            });
            //console.log(maxh);
        });
        maxh = Math.max.apply(null, oa) + 1;
        lt.eq(i).css("height", maxh);
        //console.log(maxh);
    }
};
